import 'package:fig/sqlite/sql_manager.dart';
import 'package:fig/sqlite/table_media_category.dart';

class MediaCategory {
  int id;
  int originId;
  String title;
  int createTime;

  MediaCategory({this.id, this.originId, this.title, this.createTime});

  Map<String, dynamic> toMap() {
    var map = <String, dynamic>{
      TableMediaCategory.columnOriginId: originId,
      TableMediaCategory.columnTitle: title,
      TableBase.columnCreateTime: createTime,
    };
    if (id != null) {
      map[TableBase.columnId] = id;
    }
    return map;
  }

  MediaCategory.fromMap(Map<String, dynamic> map) {
    id = map[TableBase.columnId];
    originId = map[TableMediaCategory.columnOriginId];
    title = map[TableMediaCategory.columnTitle];
    createTime = DateTime.now().millisecondsSinceEpoch;
  }

  // 将通用爬虫数据转换成业务对象
  MediaCategory.fromGeneralSpiderJson(Map<String, dynamic> map) {
    // {list_id: 1, list_name: 电影片}
    originId = map['list_id'];
    title = map['list_name'];
    createTime = DateTime.now().millisecondsSinceEpoch;
  }
}
